const mysql = require('mysql2');

// 创建数据库链接
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'mysql_password',
  database: 'orm',
})
connection.connect(function(err) {
  // 如果err有值链接失败
  if(err){
    console.error('error connecting'+err.stack);
  }
  console.log('Connected successfully.');
})

// mysql2支持两种查询模式，回调，promise
connection.query(`select * from tags where id=?`,[1],(err,result,fields)=>{
  if(err){
    console.error('error connecting'+err.stack);
    return;
  }
  console.log(result,fields);
})
